var buttonState = "1";
function ok()
{
	
	if(buttonState == "1")
	{
		buttonState = "0";
		
		var name = document.getElementById("name").value;//名字
		var cardId = document.getElementById("cardId").value;//身份证号
		var eamineeId = document.getElementById("eamineeId").value;//考生号
		var height = document.getElementById("height").value;//报名序号

		var graduationTypeSelect = document.getElementById("graduationTypeSelect");//毕业类别
		var graduationType = "";
		for(var i=0;i<graduationTypeSelect.length;i++)
		{
			if(graduationTypeSelect[i].selected)
				graduationType = graduationTypeSelect[i].value;
		}

		var examineeTypeSelect = document.getElementById("examineeTypeSelect");//考生类别
		var examineeType = "";
		for(var i=0;i<examineeTypeSelect.length;i++)
		{
			if(examineeTypeSelect[i].selected)
				examineeType = examineeTypeSelect[i].value;
		}

		var radio = document.getElementsByName("radio");//报考类别
		var applyType = "";
		for(var i=0;i<radio.length;i++)
		{
			if(radio[i].checked)
				applyType = radio[i].value;
		}

		if(name)
		{
			if((/(^\d{17}([0-9]|X|x)$)/.test(cardId)))
			{
				if((/(^(1)(8)(2)(2)\d{10}$)/.test(eamineeId)))
				{
					if((/(^[0-9a-zA-Z]{8}$)/.test(height)))
					//if((/(^\d{8}$)/.test(height)))
					{
						if(graduationType != "null")
						{
							if(examineeType != "null")
							{
								if(applyType != "")
									passByValue(name,cardId,eamineeId,height,graduationType,examineeType,applyType);
								else
									{alert("请选择报考类别");buttonState = "1";}
							}
							else
								{alert("请选择考生类别");buttonState = "1";}
						}
						else
							{alert("请选择毕业类别");buttonState = "1";}
					}
					else
						{alert("报名序号错误");buttonState = "1";}
				}
				else
					{alert("考生号错误");buttonState = "1";}
			}
			else
				{alert("身份证错误");buttonState = "1";}
		}
		else
		{
			{alert("姓名不能为空");buttonState = "1";}
		}
	}
	
}

function passByValue(name,cardId,eamineeId,height,graduationType,examineeType,applyType)
{
	
	$.ajax({
		type:'GET',
		cache:false,
		url:rootPath+"/addStudent",
		async:true,
		data:{
			name:name,
			cardId:cardId,
			eamineeId:eamineeId,
			height:height,
			graduationType:graduationType,
			examineeType:examineeType,
			applyType:applyType
		},
		success:function(result)
		{
			buttonState = "1";
			if(result.code == 100)
			{
				alert("注册成功");
				window.location.href = "index.html";
			}
			else
			{
				alert(result.extend.code);
			}
		},
		error: function(){buttonState = "1";}
	});
}

